package cc.rengu.igas.momp.common.dao.impl;

import cc.rengu.igas.momp.common.dao.McMchntAcctInfoMapper;
import cc.rengu.igas.momp.common.entity.MchntAcctInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * @author liujinan
 * @date 2021/2/27 11:21
 * @description 商户结算账户表操作接口实现
 */
public class McMchntAcctInfoMapperImpl implements McMchntAcctInfoMapper {

    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppParamConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);

    /**
     * 商户结算账户查询操作接口实现
     *
     * @param instId       法人机构号
     * @param mchntNo      商户编号
     * @param baseProdCode 基础产品代码
     * @param fundType     资金类型
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo>
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2021/2/27 10:11
     */
    @Override
    public MchntAcctInfo selectMchntAcctInfoByPrimaryKey(String instId, String mchntNo, String baseProdCode, String fundType) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MCMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "selectMompMchntAcctInfoByPrimaryKey");

        MchntAcctInfo mchntAcctInfo = new MchntAcctInfo();
        mchntAcctInfo.setInstId(instId);
        mchntAcctInfo.setMchntNo(mchntNo);
        mchntAcctInfo.setBaseProdCode(baseProdCode);
        mchntAcctInfo.setFundType(fundType);
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, mchntAcctInfo, mchntAcctInfo);
        if (0 != iReturnCode) {
            rglog.error("获取商户结算账户信息失败,instId:<{}>,mchntNo:<{}>,baseProdCode:<{}>,fundType:<{}>,iReturnCode:<{}>", instId, mchntNo, baseProdCode, fundType, iReturnCode);
            return null;
        }
        return mchntAcctInfo;
    }
}
